package com.ligy.freemarker;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Test;

import com.ligy.easypoi.model.PayeeEntity;

import freemarker.template.Configuration;
import freemarker.template.Template;

public class freemarkerTest {

	@Test
	public void test2() throws IOException {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("username", "李谷一");
		map.put("currDate", new Date());
		List<PayeeEntity> payees = new ArrayList<PayeeEntity>();
		for (int i = 0; i < 10; i++) {
			payees.add(new PayeeEntity("name" + i, "bankAccount" + i, "bankName" + i));
		}
		map.put("payees", payees);
		try {
			//通过Freemaker的Configuration读取相应的ftl
	        Configuration cfg = new Configuration();
	        //设定去哪里读取相应的ftl模板文件
	        cfg.setClassForTemplateLoading(this.getClass(),"/ftl");
	        //在模板文件目录中找到名称为name的文件
	        Template temp = cfg.getTemplate("测试用freemarker生成wor.ftl");
	        
	        FileWriter out = new FileWriter(new File("d:\\easypoi\\freemarker.doc"));
		    temp.process(map, out);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
